<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        // 查字符串也一样
        // arr='dgagjjgjsdjjsjs'\
        var arr = ['胡歌', '彭于晏', '胡歌', '胡歌', '彭于晏', '赵玉真', '赵玉真']
        var index = arr.indexOf('胡歌')
        var n = 0;
        while (index !== -1) {
            console.log(index);
            index = arr.indexOf('胡歌', index + 1)
               n++;
        }
        console.log('出现：' + n);
    </script>
</body>

</html>